import { Card, Form, FormInstance, Switch } from "antd";
import Parameter from "./Parameter"
import EmptyCard from "./EmptyCard";
import styles from '../style.less'
import CustomDraggedUpload from "@/components/CustomDraggedUpload";

interface JMXProps {
    [key: string]: any;
    form: FormInstance
}

const JMX: React.FC<JMXProps> = ({
    form
}) => {

    return <>
        <Card title="上传 JMX 脚本"
            bordered={false}
            className={styles.card}>
            <Form.Item noStyle name={['jmx', 'jmxUrl']}>
                <CustomDraggedUpload />
            </Form.Item>
        </Card>
        <Card
            title="参数化配置"
            extra={<Form.Item noStyle name={['jmx', 'enableParamConfig']}>
                <Switch checkedChildren="开启" unCheckedChildren="关闭" />
            </Form.Item>}
            bordered={false}
        >

            <Form.Item noStyle shouldUpdate={(pre, next) => pre.jmx?.enableParamConfig != next.jmx?.enableParamConfig}>
                {({ getFieldValue }) => {
                    if (getFieldValue(['jmx', 'enableParamConfig'])) {
                        return <Parameter form={form} name={['jmx', 'relation']} />
                    }
                    return <EmptyCard text="该用例未启用参数化配置。Tips: 右上角可以启用" />
                }}
            </Form.Item>
        </Card>
    </>
}

export default JMX
